package org.linlinjava.litemall.db.service;

import java.time.LocalDateTime;
import java.util.List;

import javax.annotation.Resource;

import org.linlinjava.litemall.db.dao.LitemallQuotePriceMapper;
import org.linlinjava.litemall.db.domain.LitemallFormPurchaseItem;
import org.linlinjava.litemall.db.domain.LitemallFormPurchaseItemExample;
import org.linlinjava.litemall.db.domain.LitemallQuotePrice;
import org.linlinjava.litemall.db.domain.LitemallQuotePriceExample;
import org.springframework.stereotype.Service;

@Service
public class LitemallQuotePriceService {
    @Resource
    private LitemallQuotePriceMapper quotePriceMapper;


    public void add(LitemallQuotePrice quotePrice) {
        quotePrice.setAddTime(LocalDateTime.now());
        quotePrice.setUpdateTime(LocalDateTime.now());
        quotePriceMapper.insertSelective(quotePrice);
    }

    public void addAll(List<LitemallQuotePrice> itemList) {
    	quotePriceMapper.batchInsert(itemList);
    }

    public List<LitemallQuotePrice> queryByPurchaseItemHerb(Integer purchaseItemId,Integer herbIid) {
        LitemallQuotePriceExample example = new LitemallQuotePriceExample();
        LitemallQuotePriceExample.Criteria criteria = example.createCriteria();

        criteria.andFormPurchaseItemIdEqualTo(purchaseItemId).andHerbIdEqualTo(herbIid);
        return quotePriceMapper.selectByExample(example);
    }

    public List<LitemallQuotePrice> queryByShopPurchaseItemHerb(Integer shopId,Integer purchaseItemId,Integer herbIid) {
    	LitemallQuotePriceExample example = new LitemallQuotePriceExample();
    	LitemallQuotePriceExample.Criteria criteria = example.createCriteria();
    	
    	criteria.andSupplyShopIdEqualTo(shopId).andFormPurchaseItemIdEqualTo(purchaseItemId).andHerbIdEqualTo(herbIid);
        return quotePriceMapper.selectByExample(example);
    }

    public void updateStatus(Integer id, String status) {
        LitemallQuotePrice cart = new LitemallQuotePrice();
        cart.setStatus(Byte.valueOf(status));
        LitemallQuotePriceExample example = new LitemallQuotePriceExample();
        example.or().andIdEqualTo(id);
        quotePriceMapper.updateByExampleSelective(cart, example);
    }

}
